/*
 *  ckr_spec_StringUtils_specs.cpp
 *  ckrSpec
 *
 *  Created by C. Keith Ray on 2006.11.21.
 *  Copyright 2006 __MyCompanyName__. All rights reserved.
 *
 */

#include "ckr_spec_cpp_specs.h"
#include "ckr_spec_StringUtils.h"

using namespace std;
using namespace ckr;

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

static void spec_padWithSpaces();
static void spec_padWithChar();
static void spec_failString();
static void spec_runString();
static void spec_durationString();
static void spec_tokenizeCmdString();

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

void run_stringUtil_specs()
{
	spec_padWithSpaces();
	spec_padWithChar();
	spec_failString();
	spec_runString();
	spec_durationString();
	spec_tokenizeCmdString();
}

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

static void spec_padWithSpaces()
{
	std::string actual = padWithSpaces( "abc", 5 );
	assert( actual == "abc  " );
}

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

static void spec_padWithChar()
{
	std::string actual = padWithChar( "abc", 5, '*' );
	assert( actual == "abc**" );

	actual = padWithChar( "abc", 3, '*' );
	assert( actual == "abc" );
}

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

static void spec_failString()
{
	assert( failString( true ) == "FAIL" );
	assert( failString( false ) == "pass" );
}

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

static void spec_runString()
{
	assert( runString( true ) == "yes" );
	assert( runString( false ) == "no" );
}

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

static void spec_durationString()
{
	assert( durationString( 1.0 ) == "1" );
	assert( durationString( 1.5 ) == "1.5" );
}

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

static void spec_tokenizeCmdString()
{
	{
		CmdTokenizer twoWords( "select Gold" );
		StringList strlist = twoWords.tokenizeCmdString();

		assert( strlist.size() == 2 );
		assert( strlist.at( 0 ) == "select" );
		assert( strlist.at( 1 ) == "Gold" );
	}
	{
		CmdTokenizer wordsDashed( "select one-three" );
		StringList strlist2 = wordsDashed.tokenizeCmdString();

		assert( strlist2.size() == 4 );
		assert( strlist2.at( 0 ) == "select" );
		assert( strlist2.at( 1 ) == "one" );
		assert( strlist2.at( 2 ) == "-" );
		assert( strlist2.at( 3 ) == "three" );
	}
	{
		CmdTokenizer wordsComma( "select one ,two, three" );
		StringList strlist3 = wordsComma.tokenizeCmdString();

		assert( strlist3.size() == 6 );
		assert( strlist3.at( 0 ) == "select" );
		assert( strlist3.at( 1 ) == "one" );
		assert( strlist3.at( 2 ) == "," );
		assert( strlist3.at( 3 ) == "two" );
		assert( strlist3.at( 4 ) == "," );
		assert( strlist3.at( 5 ) == "three" );
	}
}

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
